<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>BadgerDB: badgerdb::Page Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">BadgerDB
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="namespacebadgerdb.html">badgerdb</a></li><li class="navelem"><a class="el" href="classbadgerdb_1_1_page.html">Page</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pub-static-attribs">Static Public Attributes</a> &#124;
<a href="#friends">Friends</a> &#124;
<a href="classbadgerdb_1_1_page-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">badgerdb::Page Class Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Class which represents a fixed-size database page containing records.  
 <a href="classbadgerdb_1_1_page.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="page_8h_source.html">page.h</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a1e4a3930a92ed6e71ffd253cf224379a"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#a1e4a3930a92ed6e71ffd253cf224379a">Page</a> ()</td></tr>
<tr class="separator:a1e4a3930a92ed6e71ffd253cf224379a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ad0b1e85fe7849fb767dd8c21a8053cf4"><td class="memItemLeft" align="right" valign="top"><a class="el" href="structbadgerdb_1_1_record_id.html">RecordId</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#ad0b1e85fe7849fb767dd8c21a8053cf4">insertRecord</a> (const std::string &amp;record_data)</td></tr>
<tr class="separator:ad0b1e85fe7849fb767dd8c21a8053cf4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aad81fa59b469866fbd260c8a640b579f"><td class="memItemLeft" align="right" valign="top">std::string&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#aad81fa59b469866fbd260c8a640b579f">getRecord</a> (const <a class="el" href="structbadgerdb_1_1_record_id.html">RecordId</a> &amp;record_id) const</td></tr>
<tr class="separator:aad81fa59b469866fbd260c8a640b579f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae24e3f6076d6c0a18d4dd2014d540bab"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#ae24e3f6076d6c0a18d4dd2014d540bab">updateRecord</a> (const <a class="el" href="structbadgerdb_1_1_record_id.html">RecordId</a> &amp;record_id, const std::string &amp;record_data)</td></tr>
<tr class="separator:ae24e3f6076d6c0a18d4dd2014d540bab"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1bc17754b4ed548f8520a6274b3a4202"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#a1bc17754b4ed548f8520a6274b3a4202">deleteRecord</a> (const <a class="el" href="structbadgerdb_1_1_record_id.html">RecordId</a> &amp;record_id)</td></tr>
<tr class="separator:a1bc17754b4ed548f8520a6274b3a4202"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a059cb59e3ba05921f9c648fb5dba1068"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#a059cb59e3ba05921f9c648fb5dba1068">hasSpaceForRecord</a> (const std::string &amp;record_data) const</td></tr>
<tr class="separator:a059cb59e3ba05921f9c648fb5dba1068"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6f8c9e50538db4d88306b77c214c09dd"><td class="memItemLeft" align="right" valign="top">std::uint16_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#a6f8c9e50538db4d88306b77c214c09dd">getFreeSpace</a> () const</td></tr>
<tr class="separator:a6f8c9e50538db4d88306b77c214c09dd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af8416fd0be779f473c97b47e797e1c53"><td class="memItemLeft" align="right" valign="top"><a class="el" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a">PageId</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#af8416fd0be779f473c97b47e797e1c53">page_number</a> () const</td></tr>
<tr class="separator:af8416fd0be779f473c97b47e797e1c53"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9524d4507a600c1bd55bdc5b9511a484"><td class="memItemLeft" align="right" valign="top"><a class="el" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a">PageId</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#a9524d4507a600c1bd55bdc5b9511a484">next_page_number</a> () const</td></tr>
<tr class="separator:a9524d4507a600c1bd55bdc5b9511a484"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa0fdb281074cd60cb1f1d6ea6d620772"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classbadgerdb_1_1_page_iterator.html">PageIterator</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#aa0fdb281074cd60cb1f1d6ea6d620772">begin</a> ()</td></tr>
<tr class="separator:aa0fdb281074cd60cb1f1d6ea6d620772"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8e78cba69bef682a5427932485da4608"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classbadgerdb_1_1_page_iterator.html">PageIterator</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#a8e78cba69bef682a5427932485da4608">end</a> ()</td></tr>
<tr class="separator:a8e78cba69bef682a5427932485da4608"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-static-attribs"></a>
Static Public Attributes</h2></td></tr>
<tr class="memitem:ae92d52803502854f97309bae2c14ea55"><td class="memItemLeft" align="right" valign="top">static const std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#ae92d52803502854f97309bae2c14ea55">SIZE</a> = 8192</td></tr>
<tr class="separator:ae92d52803502854f97309bae2c14ea55"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a74057ec71412352ef0aa5913bbebed25"><td class="memItemLeft" align="right" valign="top">static const std::size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#a74057ec71412352ef0aa5913bbebed25">DATA_SIZE</a> = <a class="el" href="classbadgerdb_1_1_page.html#ae92d52803502854f97309bae2c14ea55">SIZE</a> - sizeof(<a class="el" href="structbadgerdb_1_1_page_header.html">PageHeader</a>)</td></tr>
<tr class="separator:a74057ec71412352ef0aa5913bbebed25"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a785a1e756d47fb7f8f3603a3fe8ffcef"><td class="memItemLeft" align="right" valign="top">static const <a class="el" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a">PageId</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#a785a1e756d47fb7f8f3603a3fe8ffcef">INVALID_NUMBER</a> = 0</td></tr>
<tr class="separator:a785a1e756d47fb7f8f3603a3fe8ffcef"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4013fab43df72bc52931241575736353"><td class="memItemLeft" align="right" valign="top">static const <a class="el" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8">SlotId</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classbadgerdb_1_1_page.html#a4013fab43df72bc52931241575736353">INVALID_SLOT</a> = 0</td></tr>
<tr class="separator:a4013fab43df72bc52931241575736353"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="friends"></a>
Friends</h2></td></tr>
<tr class="memitem:a68d15876ad188b7628261b12d0eac8aa"><td class="memItemLeft" align="right" valign="top"><a id="a68d15876ad188b7628261b12d0eac8aa"></a>
class&#160;</td><td class="memItemRight" valign="bottom"><b>File</b></td></tr>
<tr class="separator:a68d15876ad188b7628261b12d0eac8aa"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae93be65f49fbfeb5716a90719b8c4cb7"><td class="memItemLeft" align="right" valign="top"><a id="ae93be65f49fbfeb5716a90719b8c4cb7"></a>
class&#160;</td><td class="memItemRight" valign="bottom"><b>PageIterator</b></td></tr>
<tr class="separator:ae93be65f49fbfeb5716a90719b8c4cb7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a724e730c198a7a3d941f08f9653f8154"><td class="memItemLeft" align="right" valign="top"><a id="a724e730c198a7a3d941f08f9653f8154"></a>
class&#160;</td><td class="memItemRight" valign="bottom"><b>PageTest</b></td></tr>
<tr class="separator:a724e730c198a7a3d941f08f9653f8154"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aaf5d48a87d5c9424661d35cc89243a13"><td class="memItemLeft" align="right" valign="top"><a id="aaf5d48a87d5c9424661d35cc89243a13"></a>
class&#160;</td><td class="memItemRight" valign="bottom"><b>BufferTest</b></td></tr>
<tr class="separator:aaf5d48a87d5c9424661d35cc89243a13"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Class which represents a fixed-size database page containing records. </p>
<p>A page is a fixed-size unit of data storage. Each page holds zero or more records, which consist of arbitrary binary data. Records are placed into slots and identified by a <a class="el" href="structbadgerdb_1_1_record_id.html" title="Identifier for a record in a page.">RecordId</a>. Although a record's actual contents may be moved on the page, accessing a record by its slot is consistent.</p>
<dl class="section warning"><dt>Warning</dt><dd>This class is not threadsafe. </dd></dl>

<p class="definition">Definition at line <a class="el" href="page_8h_source.html#l00107">107</a> of file <a class="el" href="page_8h_source.html">page.h</a>.</p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a1e4a3930a92ed6e71ffd253cf224379a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a1e4a3930a92ed6e71ffd253cf224379a">&#9670;&nbsp;</a></span>Page()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">badgerdb::Page::Page </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Constructs a new, uninitialized page. </p>

<p class="definition">Definition at line <a class="el" href="page_8cpp_source.html#l00019">19</a> of file <a class="el" href="page_8cpp_source.html">page.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;           {</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;  initialize();</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="aa0fdb281074cd60cb1f1d6ea6d620772"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa0fdb281074cd60cb1f1d6ea6d620772">&#9670;&nbsp;</a></span>begin()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classbadgerdb_1_1_page_iterator.html">PageIterator</a> badgerdb::Page::begin </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Returns an iterator at the first record in the page.</p>
<dl class="section return"><dt>Returns</dt><dd>Iterator at first record of page. </dd></dl>

<p class="definition">Definition at line <a class="el" href="page_8cpp_source.html#l00196">196</a> of file <a class="el" href="page_8cpp_source.html">page.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;                         {</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;  <span class="keywordflow">return</span> PageIterator(<span class="keyword">this</span>);</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="a1bc17754b4ed548f8520a6274b3a4202"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a1bc17754b4ed548f8520a6274b3a4202">&#9670;&nbsp;</a></span>deleteRecord()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void badgerdb::Page::deleteRecord </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structbadgerdb_1_1_record_id.html">RecordId</a> &amp;&#160;</td>
          <td class="paramname"><em>record_id</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Deletes the record with the given ID. <a class="el" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a> is compacted upon delete to ensure that data of all records is contiguous. Slot array is compacted if the slot deleted is at the end of the slot array.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">record_id</td><td>ID of the record to delete. </td></tr>
  </table>
  </dd>
</dl>

<p class="definition">Definition at line <a class="el" href="page_8cpp_source.html#l00066">66</a> of file <a class="el" href="page_8cpp_source.html">page.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;                                                 {</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;  <a class="code" href="classbadgerdb_1_1_page.html#a1bc17754b4ed548f8520a6274b3a4202">deleteRecord</a>(record_id, <span class="keyword">true</span> <span class="comment">/* allow_slot_compaction */</span>);</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="a8e78cba69bef682a5427932485da4608"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8e78cba69bef682a5427932485da4608">&#9670;&nbsp;</a></span>end()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classbadgerdb_1_1_page_iterator.html">PageIterator</a> badgerdb::Page::end </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Returns an iterator representing the record after the last record in the page. This iterator should not be dereferenced.</p>
<dl class="section return"><dt>Returns</dt><dd>Iterator representing record after the last record in the page. </dd></dl>

<p class="definition">Definition at line <a class="el" href="page_8cpp_source.html#l00200">200</a> of file <a class="el" href="page_8cpp_source.html">page.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;                       {</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;  <span class="keyword">const</span> RecordId&amp; end_record_id = {<a class="code" href="classbadgerdb_1_1_page.html#af8416fd0be779f473c97b47e797e1c53">page_number</a>(), <a class="code" href="classbadgerdb_1_1_page.html#a4013fab43df72bc52931241575736353">Page::INVALID_SLOT</a>};</div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;  <span class="keywordflow">return</span> PageIterator(<span class="keyword">this</span>, end_record_id);</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="a6f8c9e50538db4d88306b77c214c09dd"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6f8c9e50538db4d88306b77c214c09dd">&#9670;&nbsp;</a></span>getFreeSpace()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::uint16_t badgerdb::Page::getFreeSpace </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Returns this page's free space in bytes.</p>
<dl class="section return"><dt>Returns</dt><dd>Free space in bytes. </dd></dl>

<p class="definition">Definition at line <a class="el" href="page_8h_source.html#l00185">185</a> of file <a class="el" href="page_8h_source.html">page.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;                                   { <span class="keywordflow">return</span> header_.<a class="code" href="structbadgerdb_1_1_page_header.html#a3af3c066d7651294fb3aae104f404648">free_space_upper_bound</a> -</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;                                              header_.<a class="code" href="structbadgerdb_1_1_page_header.html#ac71c5a9b3b8644da0ea827f5bd4c5742">free_space_lower_bound</a>; }</div>
</div><!-- fragment -->
</div>
</div>
<a id="aad81fa59b469866fbd260c8a640b579f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aad81fa59b469866fbd260c8a640b579f">&#9670;&nbsp;</a></span>getRecord()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">std::string badgerdb::Page::getRecord </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structbadgerdb_1_1_record_id.html">RecordId</a> &amp;&#160;</td>
          <td class="paramname"><em>record_id</em></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Returns the record with the given ID. Returned data is a copy of what is stored on the page; use updateRecord to change it.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classbadgerdb_1_1_page.html#ae24e3f6076d6c0a18d4dd2014d540bab">updateRecord</a> </dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">record_id</td><td>ID of the record to return. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>The record. </dd></dl>

<p class="definition">Definition at line <a class="el" href="page_8cpp_source.html#l00043">43</a> of file <a class="el" href="page_8cpp_source.html">page.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;                                                         {</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;  validateRecordId(record_id);</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;  <span class="keyword">const</span> PageSlot&amp; slot = getSlot(record_id.slot_number);</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;  <span class="keywordflow">return</span> data_.substr(slot.item_offset, slot.item_length);</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="a059cb59e3ba05921f9c648fb5dba1068"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a059cb59e3ba05921f9c648fb5dba1068">&#9670;&nbsp;</a></span>hasSpaceForRecord()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool badgerdb::Page::hasSpaceForRecord </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>record_data</em></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Returns true if the page has enough free space to hold the given data.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">record_data</td><td>Bytes that compose the record. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Whether the page can hold the data. </dd></dl>

<p class="definition">Definition at line <a class="el" href="page_8cpp_source.html#l00125">125</a> of file <a class="el" href="page_8cpp_source.html">page.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;                                                               {</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;  std::size_t record_size = record_data.length();</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;  <span class="keywordflow">if</span> (header_.<a class="code" href="structbadgerdb_1_1_page_header.html#a7afd8d3c6f22b25e24958ebef773175e">num_free_slots</a> == 0) {</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    record_size += <span class="keyword">sizeof</span>(PageSlot);</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;  }</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;  <span class="keywordflow">return</span> record_size &lt;= <a class="code" href="classbadgerdb_1_1_page.html#a6f8c9e50538db4d88306b77c214c09dd">getFreeSpace</a>();</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="ad0b1e85fe7849fb767dd8c21a8053cf4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ad0b1e85fe7849fb767dd8c21a8053cf4">&#9670;&nbsp;</a></span>insertRecord()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="structbadgerdb_1_1_record_id.html">RecordId</a> badgerdb::Page::insertRecord </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>record_data</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Inserts a new record into the page.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">record_data</td><td>Bytes that compose the record. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>ID of the newly inserted record. </dd></dl>

<p class="definition">Definition at line <a class="el" href="page_8cpp_source.html#l00033">33</a> of file <a class="el" href="page_8cpp_source.html">page.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;                                                        {</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="classbadgerdb_1_1_page.html#a059cb59e3ba05921f9c648fb5dba1068">hasSpaceForRecord</a>(record_data)) {</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    <span class="keywordflow">throw</span> InsufficientSpaceException(</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;        <a class="code" href="classbadgerdb_1_1_page.html#af8416fd0be779f473c97b47e797e1c53">page_number</a>(), record_data.length(), <a class="code" href="classbadgerdb_1_1_page.html#a6f8c9e50538db4d88306b77c214c09dd">getFreeSpace</a>());</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;  }</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;  <span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8">SlotId</a> slot_number = getAvailableSlot();</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;  insertRecordInSlot(slot_number, record_data);</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;  <span class="keywordflow">return</span> {<a class="code" href="classbadgerdb_1_1_page.html#af8416fd0be779f473c97b47e797e1c53">page_number</a>(), slot_number};</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="a9524d4507a600c1bd55bdc5b9511a484"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9524d4507a600c1bd55bdc5b9511a484">&#9670;&nbsp;</a></span>next_page_number()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a">PageId</a> badgerdb::Page::next_page_number </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Returns the number of the next used page this page in its file.</p>
<dl class="section return"><dt>Returns</dt><dd><a class="el" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a> number of next used page in file. </dd></dl>

<p class="definition">Definition at line <a class="el" href="page_8h_source.html#l00200">200</a> of file <a class="el" href="page_8h_source.html">page.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;{ <span class="keywordflow">return</span> header_.<a class="code" href="structbadgerdb_1_1_page_header.html#a7cb8260dedb0748d3d75c4b1722dcf3c">next_page_number</a>; }</div>
</div><!-- fragment -->
</div>
</div>
<a id="af8416fd0be779f473c97b47e797e1c53"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af8416fd0be779f473c97b47e797e1c53">&#9670;&nbsp;</a></span>page_number()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a">PageId</a> badgerdb::Page::page_number </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Returns this page's number in its file.</p>
<dl class="section return"><dt>Returns</dt><dd><a class="el" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a> number. </dd></dl>

<p class="definition">Definition at line <a class="el" href="page_8h_source.html#l00193">193</a> of file <a class="el" href="page_8h_source.html">page.h</a>.</p>
<div class="fragment"><div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;{ <span class="keywordflow">return</span> header_.<a class="code" href="structbadgerdb_1_1_page_header.html#a3f721c5ce9ef491fdc9d12292f2f4498">current_page_number</a>; }</div>
</div><!-- fragment -->
</div>
</div>
<a id="ae24e3f6076d6c0a18d4dd2014d540bab"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae24e3f6076d6c0a18d4dd2014d540bab">&#9670;&nbsp;</a></span>updateRecord()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void badgerdb::Page::updateRecord </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structbadgerdb_1_1_record_id.html">RecordId</a> &amp;&#160;</td>
          <td class="paramname"><em>record_id</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>record_data</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Updates the record with the given ID, replacing its data with a new version. This is equivalent to deleting the old record and inserting a new one, with the exception that the record ID will not change.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">record_id</td><td>ID of record to update. </td></tr>
    <tr><td class="paramname">record_data</td><td>Updated bytes that compose the record. </td></tr>
  </table>
  </dd>
</dl>

<p class="definition">Definition at line <a class="el" href="page_8cpp_source.html#l00049">49</a> of file <a class="el" href="page_8cpp_source.html">page.cpp</a>.</p>
<div class="fragment"><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;                                                      {</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;  validateRecordId(record_id);</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;  <span class="keyword">const</span> PageSlot* slot = getSlot(record_id.slot_number);</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;  <span class="keyword">const</span> std::size_t free_space_after_delete =</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;      <a class="code" href="classbadgerdb_1_1_page.html#a6f8c9e50538db4d88306b77c214c09dd">getFreeSpace</a>() + slot-&gt;item_length;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;  <span class="keywordflow">if</span> (record_data.length() &gt; free_space_after_delete) {</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keywordflow">throw</span> InsufficientSpaceException(</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        <a class="code" href="classbadgerdb_1_1_page.html#af8416fd0be779f473c97b47e797e1c53">page_number</a>(), record_data.length(), free_space_after_delete);</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;  }</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;  <span class="comment">// We have to disallow slot compaction here because we&#39;re going to place the</span></div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;  <span class="comment">// record data in the same slot, and compaction might delete the slot if we</span></div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;  <span class="comment">// permit it.</span></div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;  <a class="code" href="classbadgerdb_1_1_page.html#a1bc17754b4ed548f8520a6274b3a4202">deleteRecord</a>(record_id, <span class="keyword">false</span> <span class="comment">/* allow_slot_compaction */</span>);</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;  insertRecordInSlot(record_id.slot_number, record_data);</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<h2 class="groupheader">Member Data Documentation</h2>
<a id="a74057ec71412352ef0aa5913bbebed25"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a74057ec71412352ef0aa5913bbebed25">&#9670;&nbsp;</a></span>DATA_SIZE</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">const std::size_t badgerdb::Page::DATA_SIZE = <a class="el" href="classbadgerdb_1_1_page.html#ae92d52803502854f97309bae2c14ea55">SIZE</a> - sizeof(<a class="el" href="structbadgerdb_1_1_page_header.html">PageHeader</a>)</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Size of page free space area in bytes. </p>

<p class="definition">Definition at line <a class="el" href="page_8h_source.html#l00118">118</a> of file <a class="el" href="page_8h_source.html">page.h</a>.</p>

</div>
</div>
<a id="a785a1e756d47fb7f8f3603a3fe8ffcef"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a785a1e756d47fb7f8f3603a3fe8ffcef">&#9670;&nbsp;</a></span>INVALID_NUMBER</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">const <a class="el" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a">PageId</a> badgerdb::Page::INVALID_NUMBER = 0</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Number of page indicating that it's invalid. </p>

<p class="definition">Definition at line <a class="el" href="page_8h_source.html#l00123">123</a> of file <a class="el" href="page_8h_source.html">page.h</a>.</p>

</div>
</div>
<a id="a4013fab43df72bc52931241575736353"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4013fab43df72bc52931241575736353">&#9670;&nbsp;</a></span>INVALID_SLOT</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">const <a class="el" href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8">SlotId</a> badgerdb::Page::INVALID_SLOT = 0</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Number of slot indicating that it's invalid. </p>

<p class="definition">Definition at line <a class="el" href="page_8h_source.html#l00128">128</a> of file <a class="el" href="page_8h_source.html">page.h</a>.</p>

</div>
</div>
<a id="ae92d52803502854f97309bae2c14ea55"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae92d52803502854f97309bae2c14ea55">&#9670;&nbsp;</a></span>SIZE</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">const std::size_t badgerdb::Page::SIZE = 8192</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p><a class="el" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a> size in bytes. If this is changed, database files created with a different page size value will be unreadable by the resulting binaries. </p>

<p class="definition">Definition at line <a class="el" href="page_8h_source.html#l00113">113</a> of file <a class="el" href="page_8h_source.html">page.h</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>/home/ubuntu/study/dbmslab/lab2/BufMgr/src/<a class="el" href="page_8h_source.html">page.h</a></li>
<li>/home/ubuntu/study/dbmslab/lab2/BufMgr/src/<a class="el" href="page_8cpp_source.html">page.cpp</a></li>
</ul>
</div><!-- contents -->
<div class="ttc" id="astructbadgerdb_1_1_page_header_html_a3f721c5ce9ef491fdc9d12292f2f4498"><div class="ttname"><a href="structbadgerdb_1_1_page_header.html#a3f721c5ce9ef491fdc9d12292f2f4498">badgerdb::PageHeader::current_page_number</a></div><div class="ttdeci">PageId current_page_number</div><div class="ttdef"><b>Definition:</b> <a href="page_8h_source.html#l00053">page.h:53</a></div></div>
<div class="ttc" id="aclassbadgerdb_1_1_page_html_a059cb59e3ba05921f9c648fb5dba1068"><div class="ttname"><a href="classbadgerdb_1_1_page.html#a059cb59e3ba05921f9c648fb5dba1068">badgerdb::Page::hasSpaceForRecord</a></div><div class="ttdeci">bool hasSpaceForRecord(const std::string &amp;record_data) const</div><div class="ttdef"><b>Definition:</b> <a href="page_8cpp_source.html#l00125">page.cpp:125</a></div></div>
<div class="ttc" id="astructbadgerdb_1_1_page_header_html_ac71c5a9b3b8644da0ea827f5bd4c5742"><div class="ttname"><a href="structbadgerdb_1_1_page_header.html#ac71c5a9b3b8644da0ea827f5bd4c5742">badgerdb::PageHeader::free_space_lower_bound</a></div><div class="ttdeci">std::uint16_t free_space_lower_bound</div><div class="ttdef"><b>Definition:</b> <a href="page_8h_source.html#l00030">page.h:30</a></div></div>
<div class="ttc" id="aclassbadgerdb_1_1_page_html_a1bc17754b4ed548f8520a6274b3a4202"><div class="ttname"><a href="classbadgerdb_1_1_page.html#a1bc17754b4ed548f8520a6274b3a4202">badgerdb::Page::deleteRecord</a></div><div class="ttdeci">void deleteRecord(const RecordId &amp;record_id)</div><div class="ttdef"><b>Definition:</b> <a href="page_8cpp_source.html#l00066">page.cpp:66</a></div></div>
<div class="ttc" id="astructbadgerdb_1_1_page_header_html_a7afd8d3c6f22b25e24958ebef773175e"><div class="ttname"><a href="structbadgerdb_1_1_page_header.html#a7afd8d3c6f22b25e24958ebef773175e">badgerdb::PageHeader::num_free_slots</a></div><div class="ttdeci">SlotId num_free_slots</div><div class="ttdef"><b>Definition:</b> <a href="page_8h_source.html#l00048">page.h:48</a></div></div>
<div class="ttc" id="astructbadgerdb_1_1_page_header_html_a7cb8260dedb0748d3d75c4b1722dcf3c"><div class="ttname"><a href="structbadgerdb_1_1_page_header.html#a7cb8260dedb0748d3d75c4b1722dcf3c">badgerdb::PageHeader::next_page_number</a></div><div class="ttdeci">PageId next_page_number</div><div class="ttdef"><b>Definition:</b> <a href="page_8h_source.html#l00058">page.h:58</a></div></div>
<div class="ttc" id="aclassbadgerdb_1_1_page_html_af8416fd0be779f473c97b47e797e1c53"><div class="ttname"><a href="classbadgerdb_1_1_page.html#af8416fd0be779f473c97b47e797e1c53">badgerdb::Page::page_number</a></div><div class="ttdeci">PageId page_number() const</div><div class="ttdef"><b>Definition:</b> <a href="page_8h_source.html#l00193">page.h:193</a></div></div>
<div class="ttc" id="astructbadgerdb_1_1_page_header_html_a3af3c066d7651294fb3aae104f404648"><div class="ttname"><a href="structbadgerdb_1_1_page_header.html#a3af3c066d7651294fb3aae104f404648">badgerdb::PageHeader::free_space_upper_bound</a></div><div class="ttdeci">std::uint16_t free_space_upper_bound</div><div class="ttdef"><b>Definition:</b> <a href="page_8h_source.html#l00036">page.h:36</a></div></div>
<div class="ttc" id="aclassbadgerdb_1_1_page_html_a6f8c9e50538db4d88306b77c214c09dd"><div class="ttname"><a href="classbadgerdb_1_1_page.html#a6f8c9e50538db4d88306b77c214c09dd">badgerdb::Page::getFreeSpace</a></div><div class="ttdeci">std::uint16_t getFreeSpace() const</div><div class="ttdef"><b>Definition:</b> <a href="page_8h_source.html#l00185">page.h:185</a></div></div>
<div class="ttc" id="anamespacebadgerdb_html_afe9f2f985e7c67e04f76a16f7c4500c8"><div class="ttname"><a href="namespacebadgerdb.html#afe9f2f985e7c67e04f76a16f7c4500c8">badgerdb::SlotId</a></div><div class="ttdeci">std::uint16_t SlotId</div><div class="ttdoc">Identifier for a slot in a page.</div><div class="ttdef"><b>Definition:</b> <a href="types_8h_source.html#l00020">types.h:20</a></div></div>
<div class="ttc" id="aclassbadgerdb_1_1_page_html_a4013fab43df72bc52931241575736353"><div class="ttname"><a href="classbadgerdb_1_1_page.html#a4013fab43df72bc52931241575736353">badgerdb::Page::INVALID_SLOT</a></div><div class="ttdeci">static const SlotId INVALID_SLOT</div><div class="ttdef"><b>Definition:</b> <a href="page_8h_source.html#l00128">page.h:128</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
